package designPattern.action11.stage.c20t7.concrete;

import javax.swing.ImageIcon;

import designPattern.action11.stage.c20t7.sketch.AutoCoffeeMachine;
import designPattern.action11.stage.c20t7.sketch.State;

public class HaveCoffeeAndCoin extends State {
    AutoCoffeeMachine machine;

    public HaveCoffeeAndCoin(AutoCoffeeMachine machine) {
        this.machine = machine;
    }

    public void giveAnCupCaffee() {
        int count = machine.getCaffeeCount();
        if (count == 0) {
            machine.setState(machine.getHaveNotCaffee());
            machine.messShowing.setText("没有咖啡了");
            machine.messShowing.setIcon(new ImageIcon("/home/whcc/Disk1T/AllProjects/whccsvn/code/project/module/japp_DesigningPatten2/src/main/java/designPattern/action11/chapter20_stage/chapter20_7/res/no.jpg"));
        } else if (count == 1) {
            machine.messShowing.setIcon(new ImageIcon("/home/whcc/Disk1T/AllProjects/whccsvn/code/project/module/japp_DesigningPatten2/src/main/java/designPattern/action11/chapter20_stage/chapter20_7/res/caffee.jpg"));
            machine.setCaffeeCount(count - 1);
            showMessage();
            machine.setState(machine.getHaveNotCaffee());
        } else {
            machine.messShowing.setIcon(new ImageIcon("/home/whcc/Disk1T/AllProjects/whccsvn/code/project/module/japp_DesigningPatten2/src/main/java/designPattern/action11/chapter20_stage/chapter20_7/res/caffee.jpg"));
            machine.setCaffeeCount(count - 1);
            showMessage();
            machine.setState(machine.getHaveCoffeeNoCoin());
        }
    }

    public void showMessage() {
        machine.messShowing.setText("您得到一杯咖啡");
    }
}  

